package org.hot100_6.leetcode142;

import org.algorithm.List.ListNode;

import java.util.HashSet;

public class Solution {
    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> hashSet = new HashSet<>();

        while (head!=null){
            if (hashSet.contains(head)){
                return  head;
            }
            hashSet.add(head);
            head = head.next;

        }

        return null;
    }
}
